package org.hxyjs.service.impl;

import org.hxyjs.dao.EventDetailsDao;
import org.hxyjs.dto.DTO;
import org.hxyjs.dto.MessageEnum;
import org.hxyjs.entity.EventDetails;
import org.hxyjs.page.PageInfo;
import org.hxyjs.service.EventDetailsService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Optional;

@Service("eventdetailsService")
public class EventDetailsServiceImpl implements EventDetailsService {
    @Resource
    EventDetailsDao eventdetailsDao;

    @Override
    public DTO<EventDetails> getAllEventDetailss() throws Exception {
        List<EventDetails> eventdetailss = eventdetailsDao.getAllEventDetailss();
        //isPresent表示判断不为空成立则dto为？与：之间的对象
        MessageEnum messageEnum = Optional.ofNullable(eventdetailss).isPresent() ? MessageEnum.GETADMINSUCCESS : MessageEnum.GETADMINFAIL;
        return new DTO<EventDetails>(messageEnum.getCode(), messageEnum.getMessage(), eventdetailss);
    }

    @Override
    public DTO<EventDetails> getEventDetailsByUno(String uno) throws Exception {
        EventDetails eventdetails = eventdetailsDao.getEventDetailsByUno(uno);
        //isPresent表示判断不为空成立则dto为？与：之间的对象
        MessageEnum messageEnum = Optional.ofNullable(uno).isPresent() ? MessageEnum.GETADMINSUCCESS : MessageEnum.GETADMINFAIL;
        return new DTO<EventDetails>(messageEnum.getCode(), messageEnum.getMessage(), eventdetails);
    }

    @Override
    public DTO<EventDetails> deleteEventDetails(String uno) throws Exception {
        Integer result = eventdetailsDao.deleteEventDetails(uno);
        //isPresent表示判断不为空成立则dto为？与：之间的对象
        MessageEnum messageEnum = result > 0 ? MessageEnum.DELETEADMINSUCCESS : MessageEnum.DELETEADMINFAIL;
        return new DTO<EventDetails>(messageEnum.getCode(), messageEnum.getMessage());
    }

    @Override
    public DTO<EventDetails> updateEventDetails(EventDetails eventdetails) throws Exception {
        Integer result = eventdetailsDao.updateEventDetails(eventdetails);
        //isPresent表示判断不为空成立则dto为？与：之间的对象
        MessageEnum messageEnum = result > 0 ? MessageEnum.UPDATEADMINSUCCESS : MessageEnum.UPDATEADMINFAIL;
        return new DTO<EventDetails>(messageEnum.getCode(), messageEnum.getMessage());
    }

    @Override
    public DTO<EventDetails> addEventDetailsByUno(EventDetails eventdetails) throws Exception {
//        eventdetails.setUstate("未激活");
        Integer result = eventdetailsDao.addEventDetailsByUno(eventdetails);
//
//        //isPresent表示判断不为空成立则dto为？与：之间的对象
        MessageEnum messageEnum = result > 0 ? MessageEnum.ADDADMINSUCCESS : MessageEnum.ADDADMINFAIL;
        return new DTO<EventDetails>(messageEnum.getCode(), messageEnum.getMessage(), eventdetails);
    }

    @Override
    public DTO<EventDetails> getEventDetailssByPage(PageInfo pageInfo) throws Exception {
        List<EventDetails> eventdetailss = eventdetailsDao.getEventDetailssByPage(pageInfo);
        //isPresent表示判断不为空成立则dto为？与：之间的对象
        MessageEnum messageEnum = Optional.ofNullable(eventdetailss).isPresent() ? MessageEnum.GETADMINSUCCESS : MessageEnum.GETADMINFAIL;
        return new DTO<EventDetails>(messageEnum.getCode(), messageEnum.getMessage(), eventdetailss, pageInfo);
    }

    @Override
    public DTO<EventDetails> getEventDetailssWithOrders(String uno) throws Exception {
        return null;
    }

    /**
     * 查询MongoDB
     *
     * @param uno
     * @return
     * @throws Exception
     */

    @Override
    public DTO<EventDetails> activate(String uno) throws Exception {
//        EventDetails eventdetails = new EventDetails();
//        eventdetails.setUno(uno);
//        eventdetails.setUstate("已激活");
//        Integer result = eventdetailsDao.updateEventDetails(eventdetails);
//        //isPresent表示判断不为空成立则dto为？与：之间的对象
//        MessageEnum messageEnum = result > 0 ? MessageEnum.UPDATEADMINSUCCESS : MessageEnum.UPDATEADMINFAIL;
//        return new DTO<EventDetails>(messageEnum.getCode(), messageEnum.getMessage());
        return null;
    }

    @Override
    public DTO<EventDetails> lettory(String uno,String giftName) throws Exception {
        EventDetails eventdetails = eventdetailsDao.getEventDetailsByUno(uno);
        //isPresent表示判断不为空成立则dto为？与：之间的对象
        MessageEnum messageEnum = Optional.ofNullable(uno).isPresent() ? MessageEnum.GETADMINSUCCESS : MessageEnum.GETADMINFAIL;
        return new DTO<EventDetails>(messageEnum.getCode(), messageEnum.getMessage(), eventdetails,giftName);
    }


//    @Override
//    public DTO<Account> getAccountByAccountName(String accountName) throws Exception {
//        DTO<Account> dto = new DTO<Account>();
////        Optional<Account> adminOP = Optional.ofNullable(eventdetailsDao.getAccountByAccountName(accountName));
////        dto.setT(adminOP.get());
////        MessageEnum messageEnum = adminOP.isPresent()?MessageEnum.GETADMINSUCCESS:MessageEnum.GETADMINFAIL;
////        dto.setCode(messageEnum.getCode());
////        dto.setMsg(messageEnum.getMessage());
//        return dto;
//    }
}
